package domotica.client;

import java.util.ArrayList;

import javax.swing.JOptionPane;
import javax.xml.ws.wsaddressing.W3CEndpointReference;

import domotica.housemanager.HouseManagerImpl;
import domotica.housemanager.HouseManagerImplService;
import domotica.houseowner.HouseOwner;
import domotica.houseowner.HouseOwnerService;
import domotica.houseowner.Parameter;

public class DomoticaClient {

	public static void main(String[] args) {
		
		HouseManagerImplService houseManagerWS = new HouseManagerImplService();
		HouseManagerImpl houseManager =  houseManagerWS.getPort(HouseManagerImpl.class);
		
		W3CEndpointReference ref=houseManager.login("Andrea", "Claudia");
	
		HouseOwnerService houseOwnerWS = new HouseOwnerService();
		HouseOwner houseOwner = houseOwnerWS.getPort(ref, HouseOwner.class);
		
		ArrayList<String> actuatorSensorList = new ArrayList<String>(houseOwner.getActuatorsSensorsNameList());
		
		int i;
		int disp;
		
//		Thread t = new Thread(new EnvironmentThread(houseOwner));
//		t.start();
		
		while(true){
						
			i=1;
			for (String actuatorName: actuatorSensorList){				
				System.out.println("["+i+"] "+ actuatorName);
				i++;
			}
			
			disp=Integer.parseInt(JOptionPane.showInputDialog("Su quale dispositivo vuoi agire?"))-1;
			
			ArrayList<Parameter> actuatorSensorTaskDesiredParameterList = new ArrayList<Parameter>(houseOwner.getActuatorSensorTaskDesiredParameterList(actuatorSensorList.get(disp)));
			
			ArrayList<String> taskParameterList = new ArrayList<String>();
			
			for (Parameter parameterName: actuatorSensorTaskDesiredParameterList){				
				taskParameterList.add(JOptionPane.showInputDialog(parameterName));
			}
			
			houseOwner.addActuatorSensorTask(actuatorSensorList.get(disp), taskParameterList);
			
			System.out.println();
		}

	}

}
